#include <stdio.h>
#include <stdlib.h>

#include "binary_tree.h"


static const int MAX = 255;
static int path[MAX];
static int tail = -1;


int print_sum_path(TreeRoot root, int sum)
{
    if (NULL == root) {
    	printf("Error");
		return -1;
    }
    if (root->e > sum) {
    	//printf("Not result");
		return 1;
    }
    if (root->e == sum) {
    	for (int i = 0; i <= tail; ++i) {
	    	printf("%d ", path[i]);
	    }
	    printf("%d", root->e);
	    printf("\n");
    }
    else {
    	path[++tail] = root->e;
    	if (root->left) {
		    print_sum_path(root->left, sum-(root->e));
	    }
    	if (root->right) {
	    	print_sum_path(root->right, sum-(root->e));
	    }
	    tail--;
    }
    return 0;
    
}
/*
int main()
{
	
	TreeRoot root = create_binary_tree(10);
	insert_element_into_binary_tree(root, 5);
	insert_element_into_binary_tree(root, 12);
	insert_element_into_binary_tree(root, 4);
	insert_element_into_binary_tree(root, 7);
	//insert_element_into_binary_tree(root, 12);
	//insert_element_into_binary_tree(root, 16);
	//insert_element_into_binary_tree(root,);
	//preorder_print_binary_tree(root);
	print_sum_path(root, 22);
	
	
}
*/
